home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AttrObject.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
- #ifndef _AttrObject_
- #define _AttrObject_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifndef _Array_
- #include "Array.h"
- #endif
-
- #ifndef _Streams_
- #include "Streams.h"
- #endif
- //***************************************************************************************************
-
- const long kNoAttr = 0;
- //***************************************************************************************************
-
- typedef unsigned long TObjFlags;
- //constants for TObjFlags (returned from GetObjFlags)
-
- const TObjFlags kNoFlags = 0;
-
- const TObjFlags kHasCustomHilite = 1;
-
- const TObjFlags kNeedsIdle = 2;
-
- const TObjFlags kIndivisibleRun = 4;
- /*
- -always selected as block (clicking or shift arrow keys)
- -cleared as block (back space)
- */
-
- const TObjFlags kFixedRangeRun = 8;
- /*
- -once defined, the obj range can not be modified: other chars can not be added to or deleted from
- the same range (graphics, foot notes, TSM runs..)
- */
- //***************************************************************************************************
-
-
-
- /*constants for values returned as a feed back flags from certain object routines
- (GetAttrFlags, eventually mouseDown, ..) */
- const long kReformat = 1;
- const long kVReformat = 2;
-
- typedef unsigned long ClassId;
-
- typedef unsigned long AttrId;
-
- const short kMaxCountAttr = 32;
-
- const short kMaxAttrSize = 16;
-
- //***************************************************************************************************
-
- OSErr InitObjects();
- void EndObjects();
- //***************************************************************************************************
-
-
- struct TAttrObjModifier; //forward
-
- class CAttrObject : public HandleObject {
- public:
- CAttrObject();
-
- void IAttrObject();
- void Free();
-
- virtual void FreeData();
-
- virtual CAttrObject* CreateNew() const = 0;
- //Just do new of your class type and initialize it
-
- virtual CAttrObject* Reference();
-
- inline long GetCountReferences() {return fCountRefs;}
-
- virtual ClassId GetClassId() const = 0;
- //should be unique for each CAttrObject descendent (i.e CQDTextRun and all descendents from it have different one)
-
- virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const;
- //attrArray is allocated by the caller, just fill it
-
- virtual TObjFlags GetObjFlags();
-
- Boolean HasAttribute(AttrId theAttr) const;
-
- virtual void Assign(const CAttrObject* newVals);
-
- virtual void SetDefaults(long message = 0);
-
- long Update(const TAttrObjModifier* modifier, const CAttrObject* continuousObj =nil);
-
- long Update(const CAttrObject* srcObj, long updateMessage = 0, const CAttrObject* continuousObj =nil);
- long Update(AttrId theAttr, const void* attrBuffer, long updateMessage
- , const CAttrObject* continuousObj =nil);
- /*updateMessage, continuousObj to be passed to UpdateAttribute. The returned value is a feedBack
- flags. for each updated attribute "GetAttrFlags" is called, the ORed result is returned
- to the caller. the CAttrObject value is 0 (means no flags), descendents can override
- GetAttrFlags to return useful info like "widthChanged"(reformat), "needRedraw", ...
- */
-
- //void Complete(const CAttrObject* srcObj);
-
- Boolean Common(const CAttrObject* anObj);
- Boolean IsEqual(const CAttrObject* objectToCheck) const;
-
- inline Boolean IsInvalid() const {return (fAttr == kNoAttr);}
- virtual void Invalid();
-
- #ifdef txtnDebug
- Boolean HasAllAttributes();
- #endif
-
- Boolean GetAttributeValue(AttrId theAttr, void* attrBuffer) const;
- virtual void SetAttributeValue(AttrId theAttr, const void* attrBuffer);
-
- Boolean IsAttributeON(AttrId theAttr) const;
-
- //input/output methods
- virtual OSErr WriteToStream(CStream* outputStream);
- virtual OSErr ReadFromStream(CStream* inputStream);
-
- virtual ResType GetScrapType() const; // 0 means no data to put in the scrap
- //override if your object has a type which can be in the scrap and understood by other apps (like 'PICT' and 'snd ')
-
- virtual OSErr WriteToScrap();
- //called if GetScrapType returns != 0, may assume that ZeroScrap is called and should call PutScrap.
-
- virtual OSErr ReadFromScrap(long scrapSize);
- //called if GetScrapType returns != 0 and the type exist in the scrap, may assume that LoadScrap is already called
-
-
- protected:
- void SetAttributeON(AttrId theAttr);
-
- virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const;
- //false by default
-
- virtual Boolean SetCommonAttribute(AttrId theAttr, const void* val2Check);
-
- virtual long GetAttrFlags(AttrId theAttr, const void* attrBuffer, long updateMessage =0) const;
- /*see comment after "Update", and note that attrBuffer may be nil, in this case descendents should return a value based only
- on the AttrId.
- */
-
- virtual void UpdateAttribute(AttrId theAttr, const void* srcAttr, long updateMessage
- , const void* continuousAttr = nil);
-
- virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const;
-
- virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer);
-
- private:
- ulong fAttr;
- short fAttrRef;
- long fCountRefs;
-
- virtual void CopyAttribute(AttrId theAttr, const CAttrObject* srcObj);
- };
- //**************************************************************************************************
-
-
- struct TAttrObjModifier {
- long fMessage;
-
- CAttrObject* fObj;
-
- AttrId fAttr;
- char fAttrValue[kMaxAttrSize];
-
- TAttrObjModifier(CAttrObject* obj, long message = 0);
-
- TAttrObjModifier(AttrId attr, const void* buffer, long message = 0);
-
- TAttrObjModifier();
-
- void Set(CAttrObject* obj, long message = 0);
-
- void Set(AttrId attr, const void* buffer, long message = 0);
- };
- //***************************************************************************************************
-
-
-
- #endif
-